<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>dSFMT: dSFMT-common.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">dSFMT
   &#160;<span id="projectnumber">2.2</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.8.0 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">dSFMT-common.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="d_s_f_m_t-common_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#pragma once</span>
<a name="l00002"></a>00002 <span class="preprocessor"></span>
<a name="l00021"></a>00021 <span class="preprocessor">#ifndef DSFMT_COMMON_H</span>
<a name="l00022"></a>00022 <span class="preprocessor"></span><span class="preprocessor">#define DSFMT_COMMON_H</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;<a class="code" href="d_s_f_m_t_8h.html" title="double precision SIMD oriented Fast Mersenne Twister(dSFMT) pseudorandom number generator based on IE...">dSFMT.h</a>&quot;</span>
<a name="l00025"></a>00025 
<a name="l00026"></a>00026 <span class="preprocessor">#if defined(HAVE_SSE2)</span>
<a name="l00027"></a>00027 <span class="preprocessor"></span><span class="preprocessor">#  include &lt;emmintrin.h&gt;</span>
<a name="l00028"></a>00028 <span class="keyword">union </span>X128I_T {
<a name="l00029"></a>00029     uint64_t u[2];
<a name="l00030"></a>00030     __m128i  i128;
<a name="l00031"></a>00031 };
<a name="l00032"></a>00032 <span class="keyword">union </span>X128D_T {
<a name="l00033"></a>00033     <span class="keywordtype">double</span> d[2];
<a name="l00034"></a>00034     __m128d d128;
<a name="l00035"></a>00035 };
<a name="l00037"></a>00037 <span class="keyword">static</span> <span class="keyword">const</span> <span class="keyword">union </span>X128I_T sse2_param_mask = {{DSFMT_MSK1, DSFMT_MSK2}};
<a name="l00038"></a>00038 <span class="preprocessor">#endif</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span>
<a name="l00040"></a>00040 <span class="preprocessor">#if defined(HAVE_ALTIVEC)</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span><span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="d_s_f_m_t-common_8h.html#a43e33e2235015c9c072bad7dfe1a282c" title="This function represents the recursion formula.">do_recursion</a>(<a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *r, <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *a, <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> * b,
<a name="l00042"></a>00042                                 <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *lung) {
<a name="l00043"></a>00043     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> sl1 = ALTI_SL1;
<a name="l00044"></a>00044     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> sl1_perm = ALTI_SL1_PERM;
<a name="l00045"></a>00045     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sl1_msk = ALTI_SL1_MSK;
<a name="l00046"></a>00046     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> sr1 = ALTI_SR;
<a name="l00047"></a>00047     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> sr1_perm = ALTI_SR_PERM;
<a name="l00048"></a>00048     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sr1_msk = ALTI_SR_MSK;
<a name="l00049"></a>00049     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> perm = ALTI_PERM;
<a name="l00050"></a>00050     <span class="keyword">const</span> vector <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> msk1 = ALTI_MSK;
<a name="l00051"></a>00051     vector <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> w, x, y, z;
<a name="l00052"></a>00052 
<a name="l00053"></a>00053     z = a-&gt;s;
<a name="l00054"></a>00054     w = lung-&gt;s;
<a name="l00055"></a>00055     x = vec_perm(w, (vector <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)perm, perm);
<a name="l00056"></a>00056     y = vec_perm(z, sl1_perm, sl1_perm);
<a name="l00057"></a>00057     y = vec_sll(y, sl1);
<a name="l00058"></a>00058     y = vec_and(y, sl1_msk);
<a name="l00059"></a>00059     w = vec_xor(x, b-&gt;s);
<a name="l00060"></a>00060     w = vec_xor(w, y);
<a name="l00061"></a>00061     x = vec_perm(w, (vector <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)sr1_perm, sr1_perm);
<a name="l00062"></a>00062     x = vec_srl(x, sr1);
<a name="l00063"></a>00063     x = vec_and(x, sr1_msk);
<a name="l00064"></a>00064     y = vec_and(w, msk1);
<a name="l00065"></a>00065     z = vec_xor(z, y);
<a name="l00066"></a>00066     r-&gt;s = vec_xor(z, x);
<a name="l00067"></a>00067     lung-&gt;s = w;
<a name="l00068"></a>00068 }
<a name="l00069"></a>00069 <span class="preprocessor">#elif defined(HAVE_SSE2)</span>
<a name="l00070"></a>00070 <span class="preprocessor"></span>
<a name="l00077"></a>00077 <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="d_s_f_m_t-common_8h.html#a43e33e2235015c9c072bad7dfe1a282c" title="This function represents the recursion formula.">do_recursion</a>(<a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *r, <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *a, <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *b, <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *u) {
<a name="l00078"></a>00078     __m128i v, w, x, y, z;
<a name="l00079"></a>00079 
<a name="l00080"></a>00080     x = a-&gt;si;
<a name="l00081"></a>00081     z = _mm_slli_epi64(x, DSFMT_SL1);
<a name="l00082"></a>00082     y = _mm_shuffle_epi32(u-&gt;si, SSE2_SHUFF);
<a name="l00083"></a>00083     z = _mm_xor_si128(z, b-&gt;si);
<a name="l00084"></a>00084     y = _mm_xor_si128(y, z);
<a name="l00085"></a>00085 
<a name="l00086"></a>00086     v = _mm_srli_epi64(y, DSFMT_SR);
<a name="l00087"></a>00087     w = _mm_and_si128(y, sse2_param_mask.i128);
<a name="l00088"></a>00088     v = _mm_xor_si128(v, x);
<a name="l00089"></a>00089     v = _mm_xor_si128(v, w);
<a name="l00090"></a>00090     r-&gt;si = v;
<a name="l00091"></a>00091     u-&gt;si = y;
<a name="l00092"></a>00092 }
<a name="l00093"></a>00093 <span class="preprocessor">#else</span>
<a name="l00094"></a>00094 <span class="preprocessor"></span>
<a name="l00101"></a><a class="code" href="d_s_f_m_t-common_8h.html#a43e33e2235015c9c072bad7dfe1a282c">00101</a> <span class="keyword">inline</span> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="d_s_f_m_t-common_8h.html#a43e33e2235015c9c072bad7dfe1a282c" title="This function represents the recursion formula.">do_recursion</a>(<a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *r, <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *a, <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> * b,
<a name="l00102"></a>00102                                 <a class="code" href="union_w128___t.html" title="128-bit data structure">w128_t</a> *lung) {
<a name="l00103"></a>00103     uint64_t t0, t1, L0, L1;
<a name="l00104"></a>00104 
<a name="l00105"></a>00105     t0 = a-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[0];
<a name="l00106"></a>00106     t1 = a-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[1];
<a name="l00107"></a>00107     L0 = lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[0];
<a name="l00108"></a>00108     L1 = lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[1];
<a name="l00109"></a>00109     lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[0] = (t0 &lt;&lt; DSFMT_SL1) ^ (L1 &gt;&gt; 32) ^ (L1 &lt;&lt; 32) ^ b-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[0];
<a name="l00110"></a>00110     lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[1] = (t1 &lt;&lt; DSFMT_SL1) ^ (L0 &gt;&gt; 32) ^ (L0 &lt;&lt; 32) ^ b-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[1];
<a name="l00111"></a>00111     r-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[0] = (lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[0] &gt;&gt; DSFMT_SR) ^ (lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[0] &amp; DSFMT_MSK1) ^ t0;
<a name="l00112"></a>00112     r-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[1] = (lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[1] &gt;&gt; DSFMT_SR) ^ (lung-&gt;<a class="code" href="union_w128___t.html#a5f9319b0fdb9a62cc93fb5aade53e641">u</a>[1] &amp; DSFMT_MSK2) ^ t1;
<a name="l00113"></a>00113 }
<a name="l00114"></a>00114 <span class="preprocessor">#endif</span>
<a name="l00115"></a>00115 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
</pre></div></div><!-- contents -->


<hr class="footer"/><address class="footer"><small>
Generated on Fri Jun 29 2012 16:17:32 for dSFMT by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.0
</small></address>

</body>
</html>
